# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=bkcrack
pkgver=v1.8.1.r35.g1f34dd5
pkgrel=1
pkgdesc='Crack legacy zip encryption with Biham and Kocher known plaintext attack.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-cracker')
url='https://github.com/kimci86/bkcrack'
license=('Zlib')
depends=('gcc-libs' 'glibc')
makedepends=('git' 'cmake' 'doxygen')
optdepends=('python: deflate/inflate tools')
options=('staticlibs')
source=("git+https://github.com/kimci86/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

build() {
  local cmake_options=(
    -B build
    -S $pkgname
    -W no-dev
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    -D BKCRACK_BUILD_DOC=ON
    -D BKCRACK_BUILD_TESTING=ON
  )
  cmake "${cmake_options[@]}"
  cmake --build build
}

package() {
  cd build

  install -Dm 755 "src/cli/$pkgname" "$pkgdir/usr/bin/$pkgname"
  install -Dm 644 "src/$pkgname/libbkcrack-core.a" \
    "$pkgdir/usr/lib/libbkcrack-core.a"

  install -dm 755 "$pkgdir/usr/share/doc/$pkgname"
  cp -a doc/html "$pkgdir/usr/share/doc/$pkgname/"

  cd ../$pkgname
  install -Dm 644 license.txt -t "$pkgdir/usr/share/licenses/$pkgname"

  cp -a example "$pkgdir/usr/share/doc/$pkgname"

  install -dm 755 "$pkgdir/usr/share/$pkgname"
  cp -a tools "$pkgdir/usr/share/$pkgname/"
}

